package com.jerry.template.module.mainpage.check.activity;

import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.jerry.template.R;
import com.jerry.template.base.BaseFragment;
import com.jerry.template.module.mainpage.msg.db.DBAccess;

import butterknife.OnClick;

public class ShenHeLogin extends BaseFragment {

    private DBAccess dbAccess;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_shen_he_login;
    }

    @OnClick(R.id.btn_login)
    public void login(){

        final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

        LayoutInflater inflater = getActivity().getLayoutInflater();
        // 因为是在 Dialog 中，父视图填充 null。
        View view =  inflater.inflate(R.layout.dialog_login, null);

        final EditText userName = (EditText) view.findViewById(R.id.et_username);

        final EditText userPassword = (EditText) view.findViewById(R.id.et_userpassword);

        builder.setView(view);

        builder.setPositiveButton("登录", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int id) {
                dbAccess = new DBAccess(getContext());
                String username = userName.getText().toString().trim();
                String password = userPassword.getText().toString().trim();
                int result= dbAccess.login(username,password);
                if (result==1)
                {
                   Toast.makeText(getActivity(),"登录成功！",Toast.LENGTH_SHORT).show();
                }
                else if (result==0){
                    Toast.makeText(getActivity(),"用户名不存在！",Toast.LENGTH_SHORT).show();

                }
                else if(result==-1)
                {
                    Toast.makeText(getActivity(),"密码错误！",Toast.LENGTH_SHORT).show();
                }
            }
        });
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        });

        builder.show();
    }

    @Override
    protected void initViews() {

    }

    @Override
    protected void loadData() {

    }
}
